package com.decent.ejfadmin.user.service.impl;


import com.decent.ejfadmin.common.bean.MessageBean;
import com.decent.ejfadmin.common.bean.Page;
import com.decent.ejfadmin.common.bean.UserFeedback;
import com.decent.ejfadmin.user.dao.UserFeedbackDao;
import com.decent.ejfadmin.user.service.UserFeedbackService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

/**
 * 会员意见反馈
 *
 * @author weicx
 * @date 2018/08/20
 */
@Service
@Slf4j
public class UserFeedbackServiceImpl implements UserFeedbackService {
    @Autowired
    private UserFeedbackDao userFeedbackDao;

    /**
     * 查询会员意见反馈
     *
     * @param userFeedback 会员意见反馈
     * @param page         分页
     * @return MemberMessage
     */
    @Override
    public Page queryFeedbackPage(Page page, UserFeedback userFeedback) {
        int total = userFeedbackDao.queryFeedbackCount(userFeedback);
        page.setTotal(total);
        if (total == 0) {
            page.setResultList(new ArrayList<>());
        } else {
            page.setResultList(userFeedbackDao.queryFeedbackPage(userFeedback, page));
        }
        return page;
    }

    /**
     * 修改会员反馈
     *
     * @param userFeedback 会员意见反馈
     * @return 修改行数
     */
    @Override
    public MessageBean modifyFeedback(UserFeedback userFeedback) {
        if (userFeedbackDao.modifyFeedback(userFeedback) < 1) {
            return MessageBean.fail();
        }
        return MessageBean.success();
    }
}
